<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
        .time-item {
            width: 450px;
            height: 45px;
            margin: 0 auto;
        }

        .time-item strong {
            background: orange;
            color: #fff;
            line-height: 49px;
            font-size: 36px;
            font-family: Arial;
            padding: 0 10px;
            margin-right: 10px;
            border-radius: 5px;
            box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
        }

        .time-item>span {
            float: left;
            line-height: 49px;
            color: orange;
            font-size: 32px;
            margin: 0 10px;
            font-family: Arial, Helvetica, sans-serif;
        }

        .title {
            width: 260px;
            height: 50px;
            margin: 200px auto 50px auto;
        }
    </style>
</head>

<body>
    <h1 class="title">距离光棍节，还有</h1>

    <div class="time-item">
        <span><span id="day">00</span>天</span>
        <strong><span id="hour">00</span>时</strong>
        <strong><span id="minute">00</span>分</strong>
        <strong><span id="second">00</span>秒</strong>
    </div>
    <script>
        var day = document.getElementById('day');
        var hour = document.getElementById('hour');
        var minute = document.getElementById('minute');
        var second = document.getElementById('second');
        var times = +new Date('2021-11-11 0:0:0');
        console.log(times);
        setInterval(cong,1000);
        function cong() {
            var tm = +new Date();
            var jk = (times - tm) / 1000;
            var d = parseInt(jk / 60 / 60 / 24);
            var h = parseInt(jk / 60 / 60 % 24);
            var m = parseInt(jk / 60 % 60);
            var s = parseInt(jk % 60);
            day.innerHTML = d;
            hour.innerHTML = h < 10 ? '0' + h : h;
            minute.innerHTML = m < 10 ? '0' + m : m;
            second.innerHTML = s < 10 ? '0' + s : s;
        }
        cong();
    </script>
</body>

</html>